home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / science / ack3d.zip / ACKASM.ASM < prev    next >
Assembly Source File  |  1994-01-09  |  24KB  |  939 lines

  1. PAGE 80,132
  2. TITLE - ACKASM.ASM - Assembly routines for 3D engine
  3. .386P
  4. ;==============================================================================
  5. ; COMMAND LINE ASSEMBLY
  6. ;    MASM /B63 /Z /D_Mx FILENAME;
  7. ;
  8. ;  WHERE Mx SPECIFIES MODEL (l OR c) FOR LARGE OR COMPACT MODELS
  9. ;==============================================================================
  10.     INCLUDE        ET.EQU
  11.     INCLUDE        ET.MAC
  12.  
  13.     ANGLE_30    equ        160
  14.     ANGLE_360   equ        1920
  15.  
  16.     extrn    _bMaps:DWORD
  17.     extrn    _oMaps:DWORD
  18.     extrn    _PageBegin:WORD
  19.     extrn    _InvCosTable:DWORD
  20.     extrn    _InvSinTable:DWORD
  21.     extrn    _LongCosTable:DWORD
  22.     extrn    _DistanceTable:WORD
  23.     extrn    _AdjustTable:DWORD
  24.     extrn    _CenterRow:WORD
  25.     extrn    _MaxDistance:WORD
  26.     extrn    _TopColor:WORD
  27.     extrn    _BottomColor:WORD
  28.     extrn    _WinStartX:WORD
  29.     extrn    _WinEndX:WORD
  30.     extrn    _WinWidth:WORD
  31.     extrn    _WinColumnCount:WORD
  32.     extrn    _WinStartY:WORD
  33.     extrn    _WinEndY:WORD
  34.     extrn    _WinStartOffset:WORD
  35.     extrn    _WinLength:WORD
  36.     extrn    _WinTopLength:WORD
  37.     extrn    _WinBotLength:WORD
  38.     extrn    _WinQuadTopLength:WORD
  39.     extrn    _WinQuadBotLength:WORD
  40.     extrn    _TopLongColor:DWORD
  41.     extrn    _BotLongColor:DWORD
  42.     extrn    _lowmask:BYTE
  43.     extrn    _Walls:WORD
  44.     extrn    _ScreenBuffer:DWORD
  45.     extrn    _BkgdBuffer:DWORD
  46.     extrn    _OverlayBuffer:DWORD
  47.     extrn    _LightFlag:BYTE
  48.  
  49.     extrn    _WorkPalette:BYTE
  50.  
  51.     PEXTRN    _AckGetBitmapPtr
  52.     PEXTRN    _AckLockPtr
  53.     PEXTRN    _AckUnlockPtr
  54.  
  55.  
  56.     PUBLIC        _AckSetVGAmode
  57.     PUBLIC        _AckSetTextmode
  58.     PUBLIC        _MakeCharLong
  59.     PUBLIC        _AckDrawPage
  60.     PUBLIC        _AckSetPalette
  61.     PUBLIC        _AckBuildCeilingFloor
  62.     PUBLIC        _AckReplaceBitmap
  63.     PUBLIC        _AckOverlayBitmap
  64.  
  65.     PUBLIC        _draw_col2
  66.  
  67. SCREEN_SEG equ    0a000h    ;segment of display memory in VGA mode 13h
  68.  
  69. _TEXT    segment byte public use16 'CODE'
  70. DGROUP    group    _DATA,_BSS
  71.     assume    cs:_TEXT,ds:DGROUP
  72.  
  73. _TEXT    ends
  74. _DATA    segment word public use16 'DATA'
  75. _d@    label    byte
  76. _DATA    ends
  77. _BSS    segment word public use16 'BSS'
  78. _b@    label    byte
  79. _BSS    ends
  80.  
  81.  
  82. _TEXT    SEGMENT byte public use16 'CODE'
  83.     ASSUME cs:_TEXT
  84.  
  85. ;==============================================================================
  86. ; void AckSetVGAmode(void);
  87. ;==============================================================================
  88. PBEGIN    _AckSetVGAmode
  89.     push    bp
  90.     mov    ax,13h
  91.     int    10h        ; Set 320x200x256
  92.     pop    bp
  93.     ret
  94. _AckSetVGAmode endp
  95.  
  96. ;==============================================================================
  97. ;
  98. ;==============================================================================
  99. PBEGIN    _AckSetTextmode
  100.     push    bp
  101.     mov    ax,3
  102.     int    10h
  103.     pop    bp
  104.     ret
  105. _AckSetTextmode endp
  106.  
  107. ;==============================================================================
  108. ; Fade the screen in from black to the palette specified
  109. ; Contributed by Mark Betz
  110. ;==============================================================================
  111. AFIbeg    equ    [bp+ABASE]
  112. AFIcnt    equ    [bp+ABASE+2]
  113. AFIpal    equ    [bp+ABASE+4]
  114.  
  115. PBEGIN    _AckFadeIn
  116.     push    bp
  117.     mov    bp,sp
  118.     push    ds
  119.     push    si
  120.     push    di
  121.     mov    cx,384
  122.     xor    ax,ax
  123.     push    ds
  124.     pop    es
  125.     mov    dx,offset DGROUP:_WorkPalette
  126.  
  127.     push    dx          ; save offset of pal
  128.     xor    bx, bx          ; need to get the current palette into
  129.     mov    cx, 100h      ; pal using bios int 10h, 10h, 17h
  130.     mov    ax, 1017h      ; set up and generate the interrupt
  131.     int    10h          ; read the palette registers into pal
  132.     pop    di          ; offset of pal, was in dx!
  133.  
  134.     ; get the palette pointer, then calculate the offset to the
  135.     ; first byte processed, based on start, and the number of
  136.     ; bytes to process based on count. Use the offset to adjust
  137.     ; the string pointers in si and di, and leave the byte
  138.     ; count in ax
  139.  
  140.     lds    si, AFIpal      ; get address of target palette
  141.     mov    ax, AFIbeg      ; get offset of first palette byte to
  142.     mov    bx, 3          ; be processed
  143.     mul    bx
  144.     add    si, ax          ; adjust di and si point first byte in the
  145.     add    di, ax          ; target and temporary palettes
  146.     mov    ax, AFIcnt      ; find the number of bytes to be processed
  147.     mov    bx, 3
  148.     mul    bx          ; leave it in ax
  149.  
  150.     ; clear the bytes in the triplets which will be operated on by
  151.     ; the fade. All other registers are unaffected
  152.  
  153.     push    di          ; save the starting offset into pal
  154.     push    ax          ; save the number of bytes to process
  155.     mov    cx, ax          ; set up a loop counter
  156.     xor    ax, ax          ; clear ax
  157.     rep    stosb          ; fill relevant range of pal with 0's
  158.     pop    ax          ; restore the number of bytes to process
  159.     pop    di          ; restore the starting offset into pal
  160.     mov    cx, 64          ; 64 passes through fade loop
  161.  
  162.     ; the fade loop will execute 64 times. On each pass the inner
  163.     ; loop adjusts the working palette, then waits for a blanking
  164.     ; interval, and loads the working palette into the DAC
  165.  
  166. fade_loop:
  167.     push    cx          ; save the fade loop counter
  168.     push    di          ; save offset of first byte processed in
  169.     push    si          ; temp and target palettes
  170.     mov    bl, cl          ; outer loop count into bl
  171.     mov    cx, ax          ; load number of bytes to process into cx
  172.  
  173.     ; inner loop makes one pass through the palette for each pass
  174.     ; through the outer loop. Each byte is incremented if it's
  175.     ; target value is one greater than the outer loop count. Using
  176.     ; this logic ensures that all bytes arrive at their target values
  177.     ; on the same pass through the outer loop
  178.  
  179. pal_cmp_loop:
  180.     cmp    bl, ds:[si]      ; start incrementing when palette value
  181.     jns    no_add          ; is one greater than loop count
  182.     inc    BYTE PTR es:[di]
  183. no_add:
  184.     inc    si          ; point to the next byte in both palettes
  185.     inc    di
  186.     loop    pal_cmp_loop      ; do the next byte
  187.  
  188.     ; setup for palette load. As much as possible was moved above the
  189.     ; blanking interval wait, in order to maximize the amount of the
  190.     ; blanking interval remaining in which to do the palette loading
  191.  
  192.     mov    bx, sp
  193.     mov    di, ss:[bx+02]        ; restore offset into pal without popping
  194.     mov    cx, AFIcnt        ; number of triplets to process
  195.     push    ax            ; need to use ax for port i/o
  196.  
  197.     ; monitor bit 1 of CRT controller's input status 1 register to
  198.     ; sense a vertical blanking interval. Wait for any current vbi
  199.     ; to end, then wait for the next full one to begin.
  200.  
  201.         mov dx, 03DAh        ; CRT controller input status 1 register
  202. vbi_1:
  203.         in al, dx            ; watch vertical blanking bit
  204.         test al,08h            ; wait for it to clear to make sure
  205.         jnz vbi_1            ; we're not in a blanking interval
  206. vbi_2:
  207.         in al, dx            ; now wait for the start of the
  208.         test al,08h            ; next blanking interval
  209.         jz vbi_2
  210.  
  211.     ; load the relevant triplets from pal into the VGA DAC palette
  212.  
  213.     mov    ah, BYTE PTR AFIbeg ; get first register to process into ah
  214.     mov    dx, 03c8h        ; DAC palette index register
  215. pal_load_loop:
  216.     mov    al, ah            ; get next palette number to write
  217.     out    dx, al            ; write the register number to the dac
  218.     inc    dx            ; address dac data register
  219.     mov    al, BYTE PTR es:[di] ; get first byte of triplet
  220.     out    dx, al             ; write it to the dac data register
  221.     inc    di             ; point to second byte
  222.     mov    al, BYTE PTR es:[di] ; get second byte of triplet
  223.     out    dx, al             ; write it to the dac data register
  224.     inc    di             ; point to third byte
  225.     mov    al, BYTE PTR es:[di] ; get third byte of triplet
  226.     out    dx, al             ; write it to the dac data register
  227.     inc    di             ; point to first byte of next triplet
  228.     dec    dx             ; address the dac index register
  229.     inc    ah             ; point to next palette register
  230.     loop    pal_load_loop         ; process next triplet
  231.  
  232.     ; clean-up for the next pass through the fade loop
  233.  
  234.     pop    ax          ; restore ax
  235.     pop    si          ; restore the offset into palette
  236.     pop    di          ; restore the offset into pal
  237.     pop    cx          ; restore the fade loop counter
  238.     loop    fade_loop      ; do the next pass through the fade loop
  239.  
  240.     pop    di
  241.     pop    si
  242.     pop    ds
  243.     pop    bp
  244.     ret
  245. _AckFadeIn endp
  246.  
  247. ;==============================================================================
  248. ; void AckFadeOut(int Begin,int Count);
  249. ; Contributed by Mark Betz
  250. ;==============================================================================
  251. AFObeg    equ    [bp+ABASE]
  252. AFOcnt    equ    [bp+ABASE+2]
  253.  
  254. PBEGIN _AckFadeOut
  255.     push    bp
  256.     mov    bp,sp
  257.     push    ds
  258.     push    si
  259.     push    di
  260.  
  261.     push    ds          ; get data segment into es
  262.     pop    es
  263.     mov    dx, offset DGROUP:_WorkPalette
  264.     push    dx          ; save offset of opal
  265.     xor    bx, bx
  266.     mov    cx, 100h
  267.     mov    ax, 1017h      ; bios read dac registers function
  268.     int    10h          ; read the palette registers into opal
  269.     pop    di          ; offset of opal, was in dx!
  270.     mov    ax, AFObeg      ; get offset of first palette byte to
  271.     mov    bx, 3          ; be processed
  272.     mul    bx
  273.     add    di, ax          ; adjust offset into opal
  274.     mov    ax, AFOcnt      ; find the number of bytes to be processed
  275.     mov    bx, 3
  276.     mul    bx          ; leave it in ax
  277.     mov    cx, 64          ; 64 passes through fade loop
  278. o_fade_loop:
  279.     push    cx          ; save the fade loop counter
  280.     push    di          ; save offset of first byte processed in
  281.     mov    bl, cl          ; we'll use the pass number as a threshold
  282.     mov    cx, ax          ; load number of bytes to process into cx
  283. o_pal_cmp_loop:
  284.     cmp    bl, es:[di]      ; start decrementing when palette value
  285.     jnz    o_no_dec      ; is equal loop count (it will stay equal
  286.     dec    BYTE PTR es:[di]  ; to loop count for the rest of this pass)
  287. o_no_dec:
  288.     inc    di
  289.     loop    o_pal_cmp_loop        ; do the next byte
  290.  
  291.     mov    bx, sp            ; need the stack pointer for a moment
  292.     mov    di, ss:[bx]        ; restore offset into pal without popping
  293.     mov    cx, AFOcnt        ; number of triplets to process
  294.     push    ax            ; need to use ax for port i/o
  295.  
  296.         mov dx, 03DAh        ; CRT controller input status 1 register
  297. o_vbi_1:
  298.         in al, dx            ; watch vertical blanking bit
  299.         test al,08h            ; wait for it to clear to make sure
  300.         jnz o_vbi_1            ; we're not in a blanking interval
  301. o_vbi_2:
  302.         in al, dx            ; now wait for the start of the
  303.         test al,08h            ; next blanking interval
  304.         jz o_vbi_2
  305.  
  306.     mov    ah, BYTE PTR AFObeg ; get first register to process into ah
  307.     mov    dx, 03c8h        ; DAC palette index register
  308. o_pal_load_loop:
  309.     mov    al, ah            ; get next palette number to write
  310.     out    dx, al            ; write the register number to the dac
  311.     inc    dx            ; address dac data register
  312.     mov    al, BYTE PTR es:[di] ; get first byte of triplet
  313.     out    dx, al             ; write it to the dac data register
  314.     inc    di             ; point to second byte
  315.     mov    al, BYTE PTR es:[di] ; get second byte of triplet
  316.     out    dx, al             ; write it to the dac data register
  317.     inc    di             ; point to third byte
  318.     mov    al, BYTE PTR es:[di] ; get third byte of triplet
  319.     out    dx, al             ; write it to the dac data register
  320.     inc    di             ; point to first byte of next triplet
  321.     dec    dx             ; address the dac index register
  322.     inc    ah             ; point to next palette register
  323.     loop    o_pal_load_loop         ; process next triplet
  324.  
  325.     pop    ax          ; restore ax
  326.     pop    di          ; restore the offset into pal
  327.     pop    cx          ; restore the fade loop counter
  328.     loop    o_fade_loop      ; do the next pass through the fade loop
  329.  
  330.  
  331.  
  332.     pop    di
  333.     pop    si
  334.     pop    ds
  335.     pop    bp
  336.     ret
  337. _AckFadeOut endp
  338.  
  339.  
  340. ;==============================================================================
  341. ;
  342. ;==============================================================================
  343. MCLch    equ    [bp+ABASE]
  344.  
  345. PBEGIN    _MakeCharLong
  346.     push    bp
  347.     mov    bp,sp
  348.     mov    ax,MCLch
  349.     mov    ah,al
  350.     mov    dx,ax
  351.     pop    bp
  352.     ret
  353. _MakeCharLong endp
  354.  
  355. ;==============================================================================
  356. ; void AckDrawOverlay(UCHAR far *Screen,UCHAR far *Overlay);
  357. ;==============================================================================
  358. ADOscrn equ    [bp+ABASE]
  359. ADOover equ    [bp+ABASE+4]
  360.  
  361. PBEGIN    _AckDrawOverlay
  362.     push    bp
  363.     mov    bp,sp
  364.     push    ds
  365.     push    si
  366.     push    di
  367.     les    di,dword ptr ADOscrn
  368.     lds    si,dword ptr ADOover
  369.     mov    bx,di    ;Save screen offset
  370.     mov    ax,ds
  371.     or    ax,ax
  372.     jz    ado90
  373.  
  374. ado10:
  375.     lodsw        ;get length
  376.     or    ax,ax
  377.     jz    ado90    ;no more data
  378.     xchg    cx,ax
  379.  
  380.     lodsw        ;get offset to move to
  381.     add    di,ax
  382.     shr    cx,1
  383.   rep    movsw
  384.     rcl    cx,1    ; catch any odd byte
  385.   rep    movsb        ; move one if there is an odd byte
  386.  
  387.     mov    di,bx    ;Restore original screen offset
  388.     jmp    ado10
  389.  
  390. ado90:
  391.     pop    di
  392.     pop    si
  393.     pop    ds
  394.     pop    bp
  395.     ret
  396. _AckDrawOverlay endp
  397.  
  398. ;==============================================================================
  399. ;
  400. ; 1. Take the compiled overlay buffer and moves the non-transparent portions
  401. ;    over the top of the screen buffer.
  402. ;
  403. ; 2. Copies the area of the viewing window from the screen buffer to the
  404. ;    actual screen.
  405. ;==============================================================================
  406. DPWinStartOffset equ    [BP+ABASE]
  407. DPWinLength    equ    [BP+ABASE+2]
  408. DPScreenBuffer    equ    [BP+ABASE+4]
  409. DPWinWidth    equ    [bp+ABASE+8]
  410. DPWinHeight    equ    [bp+ABASE+10]
  411. DPWinStartX    equ    [bp+ABASE+12]
  412.  
  413. PBEGIN    _AckDrawPage
  414.     push    bp
  415.     mov    bp,sp
  416.     push    si
  417.     push    di
  418.     push    ds
  419.  
  420.     mov    cx,word ptr DPWinWidth;
  421.     mov    bx,word ptr DPWinHeight;
  422.     mov    di,word ptr DPWinStartOffset
  423.     add    di,word ptr DPWinStartX
  424.     mov    ax,SCREEN_SEG
  425.     mov    es,ax
  426.     lds    si,dword ptr DPScreenBuffer
  427.     add    si,di        ;Add starting offset to screen buffer
  428.  
  429. ;------------------------------------------------------------------------------
  430. ; Removed for now, if flicker is noticed on faster machines, then it may have
  431. ; to be put back in.
  432. ;------------------------------------------------------------------------------
  433. ;     mov     dx,3dah
  434.  
  435. ;fp030:
  436. ;     in     al,dx         ;Wait until vertical retrace is off
  437. ;     test     al,8
  438. ;     jnz     fp030
  439.  
  440. ;fp040:
  441. ;     in     al,dx         ;Wait until vertical retrace resumes
  442. ;     test     al,8
  443. ;     jz     fp040
  444.  
  445.     mov    dx,cx        ;Hold onto width
  446.     mov    ax,320
  447.     sub    ax,cx        ;get bytes to next row
  448.     dec    bx
  449.     jz    fp060
  450.  
  451. fp050:
  452.     shr    cx,1
  453.   rep    movsw
  454.     rcl    cx,1
  455.   rep    movsb
  456.     mov    cx,dx
  457.     add    di,ax
  458.     add    si,ax
  459.     dec    bx
  460.     jnz    fp050
  461.  
  462. fp060:
  463.     pop    ds
  464.     pop    di
  465.     pop    si
  466.     pop    bp
  467.     ret
  468. _AckDrawPage endp
  469.  
  470.  
  471. ;==============================================================================
  472. ; void AckSetPalette(unsigned char far *PalBuf);
  473. ;==============================================================================
  474. SPbuf    equ    [bp+ABASE]
  475.  
  476. PBEGIN    _AckSetPalette
  477.     push    bp
  478.     mov    bp,sp
  479.     push    ds
  480.     push    si
  481.  
  482.     lds    si,dword ptr SPbuf
  483.     mov    cx,256
  484.     xor    bx,bx
  485.     cld
  486.     mov    dx,3C8H
  487. sp010:
  488.     mov    al,bl
  489.     out    dx,al
  490.     inc    dx
  491.     lodsb
  492.     out    dx,al
  493.     lodsb
  494.     out    dx,al
  495.     lodsb
  496.     out    dx,al
  497.     dec    dx
  498.     inc    bx
  499.     loop    sp010
  500.  
  501.     pop    si
  502.     pop    ds
  503.     pop    bp
  504.     ret
  505. _AckSetPalette endp
  506.  
  507. ;==============================================================================
  508. ;
  509. ;void AckBuildCeilingFloor(UCHAR far *,int,int,int,int,int,int);
  510. ;==============================================================================
  511. CFBkgdBuffer    equ    [bp+ABASE]
  512. CFLightFlag    equ    [bp+ABASE+4]
  513. CFTopColor    equ    [bp+ABASE+6]
  514. CFBottomColor    equ    [bp+ABASE+8]
  515. CFWinStartY    equ    [bp+ABASE+10]
  516. CFWinEndY    equ    [bp+ABASE+12]
  517. CFCenterRow    equ    [bp+ABASE+14]
  518.  
  519. PBEGIN    _AckBuildCeilingFloor
  520.     push    bp
  521.     mov    bp,sp
  522.     push    si
  523.     push    di
  524.  
  525.     les    di,dword ptr CFBkgdBuffer
  526.     test    byte ptr CFLightFlag,1        ;Is shading on
  527.     jz    bcf_normal            ;nope
  528.     jmp    bcf_shade            ;else create shaded buffer
  529.  
  530. bcf_normal:
  531.     mov    cx,word ptr CFCenterRow
  532.     sub    cx,word ptr CFWinStartY
  533.     inc    cx
  534.     imul    cx,320
  535.     mov    ax,word ptr CFTopColor
  536.   rep    stosb                    ;no need to be fast here
  537.     mov    cx,word ptr CFWinEndY
  538.     sub    cx,word ptr CFCenterRow
  539.     imul    cx,320
  540.     mov    ax,word ptr CFBottomColor
  541.   rep    stosb
  542.     jmp    bcf_done            ;exit routine
  543.  
  544. bcf_shade:
  545.     mov    bx,word ptr CFCenterRow
  546.     sub    bx,word ptr CFWinStartY      ;Number of video rows
  547.     inc    bx
  548.     mov    cx,bx                ;Hold onto total rows
  549.     shr    bx,3                ;Turn into 8 zones
  550.     mov    ax,word ptr CFTopColor
  551.     mov    ah,al                ;Top color to use
  552.     mov    dx,4000H            ;set shading for next zone
  553.     call    FillInZone
  554.     mov    dx,4040H
  555.     call    FillInZone
  556.     mov    dx,8040H
  557.     call    FillInZone
  558.     mov    dx,8080H
  559.     call    FillInZone
  560.     mov    dx,0C080H
  561.     call    FillInZone
  562.     mov    dx,0C0C0H
  563.     call    FillInZone
  564.     mov    dx,0FFC0H
  565.     call    FillInZone        ;This takes care of top 8 zones
  566.     mov    dx,0FFFFH
  567.     call    FillInZone
  568.     xchg    ax,bx            ;ax has rows per zone
  569.     xchg    cx,bx            ;bx has total rows for top color
  570.     shl    ax,3            ;x 8 to get total rows
  571.     sub    bx,ax            ;get remaining rows if odd
  572.     jz    bcf010            ;no odd rows to fill
  573.     mov    dx,0FFFFH
  574.     call    FillInZone
  575.  
  576. bcf010:
  577.     mov    bx,word ptr CFWinEndY
  578.     sub    bx,word ptr CFCenterRow
  579.     mov    cx,bx
  580.     shr    bx,3
  581.     mov    ax,bx
  582.     shl    ax,3
  583.     sub    cx,ax        ;any odd rows to fill?
  584.     jz    bcf020        ;nope
  585.     push    bx        ;save rows per zone
  586.     mov    bx,cx
  587.     mov    dx,0FFFFH
  588.     call    FillInZone
  589.     pop    bx
  590.  
  591. bcf020:
  592.     mov    ax,word ptr CFBottomColor
  593.     mov    ah,al
  594.     mov    dx,0FFFFH
  595.     call    FillInZone
  596.     mov    dx,0FFC0H
  597.     call    FillInZone
  598.     mov    dx,0C0C0H
  599.     call    FillInZone
  600.     mov    dx,0C080H
  601.     call    FillInZone
  602.     mov    dx,8080H
  603.     call    FillInZone
  604.     mov    dx,8040H
  605.     call    FillInZone
  606.     mov    dx,4040H
  607.     call    FillInZone
  608.     mov    dx,4000H
  609.     call    FillInZone
  610.  
  611.  
  612. bcf_done:
  613.     pop    di
  614.     pop    si
  615.     mov    sp,bp
  616.     pop    bp
  617.     ret
  618. _AckBuildCeilingFloor endp
  619.  
  620.  
  621. ;==============================================================================
  622. ; Local routine, called by BuildCeilingFloor
  623. ; Entry: BX = number of rows to fill
  624. ;     DX = Shading values for odd/even rows
  625. ;     AX = base color value
  626. ;
  627. ; Exit: Di advanced bx * 160 bytes, all other registers preserved
  628. ;
  629. ;==============================================================================
  630. FillInZone proc near
  631.     push    bx
  632.     push    cx
  633.     push    si
  634.     mov    si,ax
  635.  
  636. fiz010:
  637.     test    bx,1                ;check odd/even row
  638.     jz    fiz020
  639.     or    ax,dx
  640.     jmp    short fiz030
  641. fiz020:
  642.     or    al,dh                ;swap which bytes are used
  643.     or    ah,dl
  644. fiz030:
  645.     mov    cx,160                ;move in one row
  646.    rep    stosw
  647.     mov    ax,si                ;restore base color
  648.     dec    bx                ;bump number of rows
  649.     jnz    fiz010
  650.  
  651.     pop    si
  652.     pop    cx
  653.     pop    bx
  654.     ret
  655. FillInZone endp
  656.  
  657. ;==============================================================================
  658. ; void AckReplaceBitmap(UCHAR far *xGrid,UCHAR far *yGrid,UCHAR OldBmp,UCHAR NewBmp);
  659. ; Replaces OldBmp numbers with NewBmp numbers in x and y grid arrays
  660. ;==============================================================================
  661. ARBxGrid equ    [bp+ABASE]
  662. ARByGrid equ    [bp+ABASE+4]
  663. ARBold     equ    [bp+ABASE+8]
  664. ARBnew     equ    [bp+ABASE+10]
  665.  
  666. PBEGIN    _AckReplaceBitmap
  667.     push    bp
  668.     mov    bp,sp
  669.     push    ds
  670.     push    si
  671.  
  672.     lds    si,ARBxGrid
  673.     mov    cx,4160            ;65x64
  674.     mov    bl,byte ptr ARBold
  675.     mov    bh,byte ptr ARBnew
  676.  
  677. arb010:
  678.     lodsw                ;get flags and bitmap
  679.     cmp    al,bl            ;old bitmap?
  680.     jne    arb020            ;nope
  681.     mov    ds:[si-2],bh        ;else plug in new bitmap
  682. arb020:
  683.     loop    arb010
  684.  
  685.  
  686.     lds    si,ARByGrid
  687.     mov    cx,4160            ;65x64
  688.  
  689. arb030:
  690.     lodsw                ;get flags and bitmap
  691.     cmp    al,bl            ;old bitmap?
  692.     jne    arb040            ;nope
  693.     mov    ds:[si-2],bh        ;else plug in new bitmap
  694. arb040:
  695.     loop    arb030
  696.  
  697.  
  698.     pop    si
  699.     pop    ds
  700.     pop    bp
  701.     ret
  702. _AckReplaceBitmap endp
  703.  
  704. ;==============================================================================
  705. ; void AckOverlayBitmap(UCHAR far *dest,UCHAR far *src);
  706. ; Overlays non-transparent colors of source bitmap onto destination bitmap
  707. ;==============================================================================
  708. AOBdest equ    [bp+ABASE]
  709. AOBsrc    equ    [bp+ABASE+4]
  710.  
  711. PBEGIN    _AckOverlayBitmap
  712.     push    bp
  713.     mov    bp,sp
  714.     push    ds
  715.     push    si
  716.     push    di
  717.  
  718.     push    word ptr AOBdest+2
  719.     push    word ptr AOBdest
  720.     call    _AckLockPtr
  721.     add    sp,4
  722.     or    dx,dx            ;null segment?
  723.     jz    aob090            ;yep, not enough memory
  724.  
  725.     push    dx
  726.     push    ax            ;save destination ptr
  727.  
  728.     push    word ptr AOBsrc+2
  729.     push    word ptr AOBsrc
  730.     call    _AckLockPtr
  731.     add    sp,4
  732.     or    dx,dx            ;error getting pointer?
  733.     jnz    aob010            ;nope, okay so far
  734.  
  735.     call    _AckUnlockPtr        ;Unlock the DX:AX above
  736.     add    sp,4
  737.     jmp    short aob090
  738.  
  739.  
  740. aob010:
  741.     mov    fs,dx
  742.     mov    si,ax            ;Source
  743.     mov    bx,ax            ;Hold onto source offset
  744.  
  745.     pop    di
  746.     pop    es            ;Get destination from DX:AX above
  747.     mov    dx,di            ;hold onto destination offset
  748.  
  749.     mov    cx,4096            ;64x64 bitmap
  750.  
  751. aob020:
  752.     mov    al,fs:[si]        ;get source pixel
  753.     or    al,al
  754.     jz    aob030
  755.     mov    es:[di],al
  756.  
  757. aob030:
  758.     inc    si
  759.     inc    di
  760.     loop    aob020
  761.  
  762.     push    es
  763.     push    dx            ;dest bitmap
  764.  
  765.     push    fs
  766.     push    bx            ;source bitmap
  767.     call    _AckUnlockPtr
  768.     add    sp,4
  769.  
  770.     call    _AckUnlockPtr        ;now unlock destination
  771.     add    sp,4
  772.  
  773. aob090:
  774.     pop    di
  775.     pop    si
  776.     pop    ds
  777.     pop    bp
  778.     ret
  779. _AckOverlayBitmap endp
  780.  
  781. ;==============================================================================
  782. ; AckCopyBackground(UCHAR far *scrn,UCHAR far *bkgd,int len,int offset);
  783. ;==============================================================================
  784. ACBscrn equ    [bp+ABASE]
  785. ACBbkgd equ    [bp+ABASE+4]
  786. ACBlen    equ    [bp+ABASE+8]
  787. ACBoff    equ    [bp+ABASE+10]
  788.  
  789. PBEGIN _AckCopyBackground
  790.     push    bp
  791.     mov    bp,sp
  792.     push    ds
  793.     push    si
  794.     push    di
  795.  
  796. ;------------------------------------------------------------------------------
  797. ; Quickly transfer the pre-built background ceiling and floor to the screen.
  798. ;------------------------------------------------------------------------------
  799.     les    di,dword ptr ACBscrn
  800.  
  801.     add    di,word ptr ACBoff
  802.     mov    cx,word ptr ACBlen          ;Number of DWORDS to move
  803.     lds    si,dword ptr ACBbkgd          ;Pre-built buffer
  804.   rep    movsd
  805.  
  806.     pop    di
  807.     pop    si
  808.     pop    ds
  809.     pop    bp
  810.     ret
  811. _AckCopyBackground endp
  812.  
  813.  
  814. ;==============================================================================
  815. ; draw_col2(int Col,int slice,int dist,int width,int ht,UCHAR far *Wall,
  816. ;        UCHAR far *Screen,UCHAR far *Pal,int light,int offset);
  817. ; Contributed by Jaimi McEntire
  818. ;==============================================================================
  819.  
  820. DCcol    equ    [bp+ABASE]
  821. DCslice equ    [bp+ABASE+2]
  822. DCdist    equ    [bp+ABASE+4]
  823. DCwidth equ    [bp+ABASE+6]
  824. DCht    equ    [bp+ABASE+8]
  825. DCwall    equ    [bp+ABASE+10]
  826. DCscrn    equ    [bp+ABASE+14]
  827. DCPal    equ    [bp+ABASE+18]
  828. DClight equ    [bp+ABASE+22]
  829. DChoff    equ    [bp+ABASE+24]
  830.  
  831. DCangle equ    [bp-2]
  832.  
  833. PBEGIN _draw_col2
  834.     push    bp
  835.     mov    bp,sp
  836.     sub    sp,4
  837.     push    ds
  838.     push    si
  839.     push    di
  840.  
  841.     mov    word ptr DCangle,0
  842.     mov    edx,0
  843.     mov    esi,0
  844.  
  845.     mov    ax,DCdist     ; get distance to object
  846.     shr    ax,6         ; divide it by 64 to get zones.
  847.  
  848.     cmp    ax,15         ; make sure zone doesn't go beyond 15
  849.     jl    zoneokay
  850.     mov    ax,15
  851.  
  852. zoneokay:
  853. ; Good place for light modifier to modify zone
  854.      shl ax,8         ; mult by 256 to get offset into paltables.
  855.      lfs dx,dword ptr DCPal     ; point FS:DX at PalTables
  856.      cmp    word ptr DClight,0
  857.      jz    zonelight
  858.      add dx,ax         ; FS:DX points to corrected palette for zone.
  859.  
  860. zonelight:
  861.      les di,dword ptr DCscrn ; ES:DI point to area we are painting
  862.  
  863. ;/     mov ax,column
  864. ;/     cmp ax,ViewX
  865. ;/     jl  outtahere         ; don't bother to draw a column we wont see.
  866. ;/     cmp ax,ViewX2
  867. ;/     jge outtahere
  868. ;/     sub ax,ViewX
  869. ;/     mov column,ax         ; adjust column for offset into buffer.
  870.  
  871.     lds    si,DCwall     ; DS:SI point to wall buffer
  872.  
  873. ;;;    mov    bx,DCht         ; center row.
  874. ;;;    imul    bx,word ptr DCwidth
  875.     mov    bx,DChoff     ; Pick up offset to center of viewport
  876.     add    bx,word ptr DCcol
  877.     add    di,bx         ; es:di now point at starting area (top run)
  878.     mov    bx,di
  879.     add    bx,DCwidth     ; es:bx points to 1 down (for bottom run)
  880.  
  881.     mov    cx,0         ; ht.
  882.     mov    ax,DCslice
  883.     shl    ax,6         ; mult slice by 64
  884.     add    ax,si         ; add in offset to wall bitmap
  885.     mov    DCslice,ax     ; save it
  886.     mov    eax,0
  887.  
  888. looptop:
  889.     movzx    ax,ch         ; current ht
  890.     mov    si,31         ; base to start with
  891.     sub    si,ax         ; base - ht = row
  892.     add    si,DCslice     ; plus column start to point at the pixel.
  893.     mov    al,ds:[si]     ; mov al,offset slice[esi]
  894.     or    al,al         ; see if transparent
  895.     jz    blank         ; yes, don't draw this pixel
  896.     mov    al,fs:[edx][eax] ; added this line to get correct shading.
  897.     mov    es:[di],al
  898.  
  899. blank:
  900.     movzx    si,ch        ; use a cool 386 instruction to accomplish
  901.     add    si,32        ;  same as mov ax,cx; shr ax,8 !!
  902.     add    si,DCslice    ; add in starting column
  903.     mov    al,ds:[si]
  904.     or    al,al
  905.     je    blank2
  906.     mov    al,fs:[edx][eax]     ; added this line to shade it.
  907.     mov    es:[bx],al
  908.  
  909. blank2:
  910.     mov    ax,DCwidth
  911.     sub    di,ax             ; point to the next two dest pixels.
  912.     add    bx,ax             ; point to the next two dest pixels.
  913.     add    cx,word ptr DCdist     ; add distance to ht adjuster.
  914.  
  915.     cmp    ch,32             ; cmp to 32 (1 half our bm size)
  916.     jge    outtahere         ; get out if bitmap done.
  917.  
  918. ;;;;    inc    word ptr DCangle
  919.     mov    ax,DCangle
  920.     inc    ax
  921.     cmp    ax,word ptr DCht     ; if half height,
  922.     jge    outtahere         ; then leave.
  923.     mov    DCangle,ax
  924.     jmp    looptop
  925.  
  926. outtahere:
  927.  
  928.     pop    di
  929.     pop    si
  930.     pop    ds
  931.     mov    sp,bp
  932.     pop    bp
  933.     ret
  934. _draw_col2 endp
  935.  
  936. _TEXT    ENDS
  937.     END
  938.  
  939.